﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Ec_System.Models.Web;
using Ec_System.Bll.Web;
using Ec_System.API;

namespace Ec_System.Cache.Web
{
    public  class AdRecommendCache
    {
        AdRecommendManager adRecommendManager = new AdRecommendManager();
        /// <summary>
        /// 从缓存读取广告信息
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public List<AdRecommendData> GetAdRecommendByKey(string key)
        {
            
            //从缓冲中读取
            var ad = RedisHelper.Get<List<AdRecommendData>>("A" + key);

            //如果缓冲中没有对应的数据,则中数据库中读取
            if(ad == null)
            {
                ad = adRecommendManager.GetAdRecommendByKey(key);
                RedisHelper.Set<List<AdRecommendData>>("A" + key, ad, 30);
            }

            return ad;
            
            //为了方便暂时不跑缓存
            //return adRecommendManager.GetAdRecommendByKey(key);
        }
    }
}
